package domain;

import java.util.ArrayList;
import java.util.List;

import domain.enums.GameStatus;

public class Game 
{

	private Board board;
	private boolean aiBlack;
	private int depth;
	
	//note to self - test on school computer for the 3 seconds issue
	
	public Game(boolean isBlack)
	{
		depth = 4; //5 is beyond can't be compiled
		board = new Board();
		this.aiBlack = isBlack;
	}
	
	public ArrayList<Player> getBlack()
	{
		return board.blackPlayers;
	}
	
	public ArrayList<Player> getWhite()
	{
		return board.whitePlayers;
	}
	
	//draw board
	@Override public String toString()
	{
		String theBoard;
		
		theBoard = "   A B C D E F G H \n";;
		
		for(int y=0; y<getBoardWidth(); y++)
		{
			theBoard += ((getBoardWidth() - y) + " ");
			
			for(int x=0; x<getBoardWidth(); x++)
			{
				theBoard += "|";
				theBoard += board.tileOccupied(x, y);
			}
			
			theBoard += "|\n";
		}
		
		return theBoard;
	}
	
	public int getBoardWidth()
	{
		return board.ROWS;
	}
	
	public List<Position> getAvailableMoves()
	{
		return board.getAvailableMoves();
	}
	
	public boolean validMove(Move move)
	{
		
		if(getAvailableMoves().contains(move.getPosition()))
		{
			board.PerformMove(move);
			return true;
		}
		
		return false;
	}
	
	public GameStatus getGameStatus()
	{
		return board.getGameStatus();
	}
	
	public Move getAIMove()
	{
		Minimax mm = new Minimax(aiBlack, new Board(board), depth);
		return mm.getNextMove();
	}
}
